package com.ivi.car.module.store.presenter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.ivi.car.R;
import com.ivi.car.module.store.model.StoreBean;
import com.ivi.car.module.store.view.adapter.StoreAdapter;
import com.wm.machine.baselibrary.common.widget.recyclerview.itemdecoration.SpaceItemDecoration;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by wjj on 2018/3/6.
 */

public class StorePresenter implements IStorePresenter {
    private List<StoreBean> showData = new ArrayList<>();

    @Override
    public String getAddressName() {
        return "上海";
    }


    /**
     * 展示数据
     *
     * @param recyclerView 展示recyclerview数据
     * @param manager      管理布局样式
     * @param decoration   子布局距离
     */
    @Override
    public void showList(final RecyclerView recyclerView, LinearLayoutManager manager, SpaceItemDecoration decoration) {
        getData();
        recyclerView.addItemDecoration(decoration);
        recyclerView.setLayoutManager(manager);
        final StoreAdapter storeAdapter = new StoreAdapter(R.layout.item_store, showData);
        recyclerView.setAdapter(storeAdapter);
        storeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (int i = 0; i < showData.size(); i++) {
                    StoreBean storeBean = showData.get(i);
                    if (i == position) {
                        storeBean.setSelect(true);
                    } else {
                        storeBean.setSelect(false);
                    }
                }
                storeAdapter.notifyDataSetChanged();
            }
        });
    }
    private final  int num = 50;
    /**
     * 获取数据
     */
    private void getData() {
        String url = "http://img2.imgtn.bdimg.com/it/u=3812628672,1278638280&fm=27&gp=0.jpg";
        for (int i = 0; i < num; i++) {
            StoreBean storeBean = new StoreBean();
            storeBean.setRecommend(true);
            storeBean.setStoreUrl(url);
            storeBean.setYiZhan(true);
            storeBean.setStoreDistance("1.1公里");
            storeBean.setStoreName("威马4S店");
            storeBean.setStoreAddress("天河公路999号");
            showData.add(storeBean);
        }
        for (int i = 0; i < num; i++) {
            StoreBean storeBean = new StoreBean();
            storeBean.setRecommend(false);
            storeBean.setStoreUrl(url);
            storeBean.setYiZhan(false);
            storeBean.setStoreDistance("2.5公里");
            storeBean.setStoreName("威马4S店");
            storeBean.setStoreAddress("曹安公路1358号");
            showData.add(storeBean);
        }
    }
}
